#ifndef _WEB_SHTTPD_H_
#define _WEB_SHTTPD_H_

#include "../../libshttpd/defs.h"
#include <sys/select.h>
#include <string>

typedef enum uri_type{ROOT_BODE= 0,INVALID}URI_TYPE; //动态增减
class http_event
{
public:
    virtual std::string on_message(std::string struri, std::string strmsg) = 0;
    virtual int err_message() = 0;
};

struct event_data{
    URI_TYPE uritype;
    http_event *event;
    void *data; //用户数据
};

struct err_data{
    int err; //40x
    http_event *event;
    void *data;
};

class web_httpd 
{
public:
    web_httpd(http_event *pevent);

    virtual ~web_httpd();

    int init(int argc, char *argv[]);

    void fini();

    int set_option(const char *opt, const char *val);

    void register_uri(const char *uri, void *const user_data);

    void web_poll(int milliseconds);

    const char *version(void);

    int get_var(const char *var, const char *buf, int buf_len,
        char *value, int value_len);

    const char *web_get_header(struct shttpd_arg * arg, const char *header_name);

    const char *web_get_env(struct shttpd_arg *arg, const char *name);

    void get_http_version(struct shttpd_arg *arg,
            unsigned long *major, unsigned long *minor);

    size_t web_printf(struct shttpd_arg *arg, const char *fmt, ...);

    void handle_error(int status, void *const data);

    void register_ssi_func(const char *name, void *const user_data);

    void wakeup(const void *priv);

    int web_join(fd_set *read_set, fd_set *write_set, int *max_fd);

    int  socketpair(int sp[2]);

private:

    URI_TYPE get_uri_type(const char *uri);

/*
struct shttpd_ctx *
int shttpd_set_option(struct shttpd_ctx *, const char *opt, const char *val);
void shttpd_fini(struct shttpd_ctx *);
void shttpd_register_uri(struct shttpd_ctx *ctx, const char *uri,
		shttpd_callback_t callback, void *const user_data);
void shttpd_poll(struct shttpd_ctx *, int milliseconds);
const char *shttpd_version(void);
int shttpd_get_var(const char *var, const char *buf, int buf_len,
		char *value, int value_len);
const char *shttpd_get_header(struct shttpd_arg *, const char *header_name);
const char *shttpd_get_env(struct shttpd_arg *, const char *name);
void shttpd_get_http_version(struct shttpd_arg *,
		unsigned long *major, unsigned long *minor);
size_t shttpd_printf(struct shttpd_arg *, const char *fmt, ...);
void shttpd_handle_error(struct shttpd_ctx *ctx, int status,
		shttpd_callback_t func, void *const data);
void shttpd_register_ssi_func(struct shttpd_ctx *ctx, const char *name,
		shttpd_callback_t func, void *const user_data);
void shttpd_wakeup(const void *priv);
int shttpd_join(struct shttpd_ctx *, fd_set *, fd_set *, int *max_fd);
int  shttpd_socketpair(int sp[2]);
*/
    
private:
    struct shttpd_ctx* _pctx;
    http_event* _event;
};


#endif /*_WEB_SHTTPD_H_*/
